const Nedb = require('nedb')

const nedb = new Nedb({
  filename: '/database/nedb.db',
  autoload: true
})

class NedbUtils {
  static insertData = (doc, callback) => {
    // eslint-disable-next-line handle-callback-err
    return nedb.insert(doc, (err, newDoc) => {
      callback(newDoc)
    })
  }
  static selectData = (doc, callback) => {
    // eslint-disable-next-line handle-callback-err
    return nedb.find(doc).sort({name: 1}).exec(function (err, docs) {
      callback(docs)
    })
  }
}

export default NedbUtils
